<?php

//This output goes into #right_nav_container_ajax div tag of default.ctp

echo $form->create(null, array('url' => '/waiters/ajxOrder'));
if (isset($output) && is_array($output)) {

    if (count($output) > 0) {
        e("Click to remove item");

        e("<table border=1>");
        //debug($output);
        $total = 0.00;
        foreach ($output as $menu_item_id => $detailsArray) {
            //$detailsArray data structure is defined in  writingpad_controller
            $name = $detailsArray["from_writingpad_menu_item_name"];
            $nameLink = $ajax->link(
                            $name,
                            array('controller' => 'waiters', 'action' => 'removeItemFromOrder', $menu_item_id),
                            array('update' => 'right_nav_container_ajax'),
                            'Removing ' . $name . ' from order. Okey?'
            );
            $qty = $detailsArray["from_writingpad_quantity"];
            $price = $detailsArray["from_writingpad_price"];
            $itemCost = $qty * $price;
            $total = $total + ($itemCost);
            e("<tr>");
            e("<td>" . /* $name . " " . */ $nameLink . "</td>" . "<td>" . $qty . "</td>" . "<td>$" . $itemCost . "</td>");
            e("</tr>");
        }
        e("<tr>");
        e("<td colspan=2>" . "Total" . "</td>" . "<td>$" . $total . "</td>");
        e("</tr>");
        e("</table>");

        $textLinkMetaData = array(
            "controller" => "orders",
            "action" => "add"
        );
        $placeOrderTextLink = $html->link("Place order", $textLinkMetaData);

        $imageLinkMetaData = array(
            "alt" => $placeOrderTextLink,
            'url' => $textLinkMetaData
        );
        $placeOrderImageLink = $html->image("place_order.jpg", $imageLinkMetaData);

        echo $placeOrderImageLink." | ".$placeOrderTextLink;


        echo " <br/> ";

        $textLinkMetaData = array('controller' => 'waiters', 'action' => 'cancelOrder', $order_token);

        $cancelOrderTextLink = $ajax->link(
                        'Cancel Order',
                        $textLinkMetaData,
                        array('update' => 'right_nav_container_ajax'),
                        'No no no... u cancelling... Why cancel? R u sure?'
        );
        $imageLinkMetaData = array(
            "alt" => $cancelOrderTextLink,
            'url' => $textLinkMetaData
        );
        $cancelOrderImageLink = $this->Html->image("cancel_order.jpg", $imageLinkMetaData);

        echo $cancelOrderImageLink." | ".$cancelOrderTextLink;
    }
    echo $form->hidden("order_token", array("value" => $order_token));
    echo $form->end();
}
?>